package com.example.shop.dao;

import com.example.shop.entity.User;
import com.example.shop.model.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

/**
 * author: adnaan
 * create: 2023-11-07 13:48
 * Description:
 */
@Component
public class UserDao {

    @Autowired
    private MongoTemplate mongoTemplate;

    public User get(Query query) {
        return mongoTemplate.findOne(query, User.class);
    }

    public Object save(User s) {
        return mongoTemplate.save(s);
    }

    public ApiResponse update(Query query, Update update) {
        return ApiResponse.success("200","下单成功",mongoTemplate.updateMulti(query, update, User.class));
    }
}
